Path: blob/master/Part 3 - Classification/Kernel SVM/[Python] Kernel SVM.ipynb
1009 views
Kernel: Python 3
Kernel SVM
Data preprocessing
In [2]:
In [3]:
In [4]:
Out[4]:
In [5]:
In [6]:
Out[6]:
array([[ 27, 57000],
[ 46, 28000],
[ 39, 134000],
[ 44, 39000],
[ 57, 26000],
[ 32, 120000],
[ 41, 52000],
[ 48, 74000],
[ 26, 86000],
[ 22, 81000]])
In [7]:
Out[7]:
array([[ 46, 22000],
[ 59, 88000],
[ 28, 44000],
[ 48, 96000],
[ 29, 28000],
[ 30, 62000],
[ 47, 107000],
[ 29, 83000],
[ 40, 75000],
[ 42, 65000]])
In [8]:
Out[8]:
array([0, 1, 1, 0, 1, 1, 0, 1, 0, 0])
In [9]:
Out[9]:
array([0, 1, 0, 1, 0, 0, 1, 0, 0, 0])
In [22]:
In [24]:
Out[24]:
array([[-1.06675246, -0.38634438],
[ 0.79753468, -1.22993871],
[ 0.11069205, 1.853544 ],
[ 0.60129393, -0.90995465],
[ 1.87685881, -1.28811763],
[-0.57615058, 1.44629156],
[ 0.3069328 , -0.53179168],
[ 0.99377543, 0.10817643],
[-1.16487283, 0.45724994],
[-1.55735433, 0.31180264]])
In [25]:
Out[25]:
array([[ 0.79753468, -1.40447546],
[ 2.07309956, 0.51542886],
[-0.96863208, -0.76450736],
[ 0.99377543, 0.74814454],
[-0.87051171, -1.22993871],
[-0.77239133, -0.24089709],
[ 0.89565505, 1.06812859],
[-0.87051171, 0.36998156],
[ 0.20881242, 0.13726589],
[ 0.40505317, -0.15362871]])
Fitting Kernel SVM classifier to the Training set
In [12]:
Out[12]:
SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
decision_function_shape='ovr', degree=3, gamma='auto', kernel='rbf',
max_iter=-1, probability=False, random_state=42, shrinking=True,
tol=0.001, verbose=False)
Predicting the Test set results
In [13]:
In [14]:
Out[14]:
array([1, 1, 0, 1, 0, 0, 1, 0, 0, 0])
In [15]:
Out[15]:
array([0, 1, 0, 1, 0, 0, 1, 0, 0, 0])
Making the Confusion Matrix
In [16]:
Out[16]:
array([[47, 5],
[ 1, 27]])
classifier made 47 + 27 = 74 correct prediction and 5 + 1 = 6 incoreect predictions.
Visualising the Training set results
In [21]:
Out[21]:
Visualising the Test set results
In [20]:
Out[20]:
Looks like it is much better the Linear kernel.